//
//  AccountBookStyleViewController.m
//  ProjectOneDemo
//
//  Created by dllo on 16/5/18.
//  Copyright © 2016年 wjg. All rights reserved.
//

#import "AccountBookStyleViewController.h"
#import "AccountBookStyleDetailCell.h"
#define WIDTH [UIScreen mainScreen].bounds.size.width
#import "Common.h"

@interface AccountBookStyleViewController ()<UICollectionViewDataSource, UICollectionViewDelegate>

@property (nonatomic , strong)UICollectionView *collectionView;
@property (nonatomic, strong)NSArray *picArr;
@property (nonatomic, strong) UIButton *backButton;

@property (nonatomic, strong) UIView *lineView;

@end

@implementation AccountBookStyleViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self createView];
    
}
- (void)createView {
    self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
    
    self.lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 40, MAIN_WIDTH, 1)];
    [self.navigationController.navigationBar addSubview:_lineView];
    self.lineView.backgroundColor = LIGHT_GRAY;
    
    self.backButton = ({
        BaseButton *tempButton = [BaseButton buttonWithType:UIButtonTypeCustom];
        tempButton.frame = CGRectMake(5 / 414.0 * MAIN_WIDTH, 8, 30 / 414.0 * MAIN_WIDTH, 25 / 414.0 * MAIN_WIDTH);
        [self.navigationController.navigationBar addSubview:tempButton];
        [tempButton setImage:[UIImage imageNamed:@"fanhui.png"] forState:UIControlStateNormal];
        [tempButton addTarget:self action:@selector(backButtonAction:) forControlEvents:UIControlEventTouchUpInside];
        tempButton;
    });
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.itemSize = CGSizeMake(WIDTH / 3, WIDTH / 3);
    layout.minimumInteritemSpacing = 0;
    layout.minimumLineSpacing = 0;
    
    self.collectionView = [[UICollectionView alloc]initWithFrame:self.view.frame collectionViewLayout:layout];
    self.collectionView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.collectionView];
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    
    [self.collectionView registerClass:[AccountBookStyleDetailCell class] forCellWithReuseIdentifier:NSStringFromClass([AccountBookStyleDetailCell class])];
    
    

    self.picArr = @[@"AccountBookCover1.png", @"AccountBookCover2.png", @"AccountBookCover3.png", @"AccountBookCover4.png", @"AccountBookCover5.png", @"AccountBookCover6.png"];
    
    
    

}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 6;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    AccountBookStyleDetailCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([AccountBookStyleDetailCell class]) forIndexPath:indexPath];
    cell.picImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@", self.picArr[indexPath.row]]];
    
    
    return cell;
    
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    [self.delegate sendIndex:indexPath.row];
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}

- (void)backButtonAction:(UIButton *)button {
    [self dismissViewControllerAnimated:YES completion:^{
        
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
